use strict;

my @result;
my @files;
tree($ARGV[0]);

open RE, ">../../data/product_category";
foreach(@result){
	print RE $_,"\n";
}
close(RE);


sub tree
{
        my $path=shift;
        my @files;
        
        opendir(THISDIR,$path);
        @files=readdir THISDIR;
        closedir THISDIR;
        
        my $cate=substr($path,length($path)-5,5);
        
        for(@files)
        {
                next if(/^\.$/);
                next if(/^\.\.$/);
                if(-d $path.'/'.$_)
                {
                        tree($path.'\\'.$_);
                }
                else
                {
                	my $filename=substr($_,0,index($_,'.'));

                	open FILE, "<$path".'\\'."$_";

									while(<FILE>){
										if(/Main-column8-b/){
											/http:\/\/jsbcmall\.com\/product\/productCateFilter\.action\?cateId=(\d+).*http:\/\/jsbcmall\.com\/product\/productCateFilter\.action\?cateId=(\d+)/;
											if($1 ne $cate and $2 ne $cate and $cate ne "oduct"){
												push @result,$filename.' '.$1.' '.$2.' '.$cate;
												print $filename.' '.$1.' '.$2.' '.$cate."\n";	
											}else{
												push @result,$filename.' '.$1.' '.$2;
												print $filename.' '.$1.' '.$2."\n";	
											}
										}
									}
									
									close(FILE);
                        
                }
        }
        return;
}